<template>
  <div class="businessUnit">
    <topBar :title="title"></topBar>
    <div class="connet">
      <div class="text">
        <div>
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ monthFrom }}</div>
          </div>
          <p>
            <span class="circle"></span
            ><span class="msg">{{ increaseFrom }}</span>
          </p>
          <p>
            <span class="circle"></span><span class="msg">{{ downFrom }}</span>
          </p>
          <p>
            <span class="circle"></span><span class="msg">{{ allFrom }}</span>
          </p>
        </div>
      </div>
      <div class="table">
        <el-table
          :data="tableData"
          border
          :span-method="objectMethod"
          :cell-style="cellStyle"
          :header-cell-style="{
            background: '#FFC000',
            color: '#000000',
            padding: '0',
            height: '26px',
          }"
        >
          <el-table-column
            v-for="(item, index) in tableTitle"
            :label="item"
            :key="index"
            align="center"
            :style="{ padding: '0px' }"
          >
            <template slot-scope="scope">
              <span v-if="index < 5">{{ scope.row["name" + index] }}</span>
              <span v-else>{{ scope.row["fee" + (index - 5)] }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "./topBar";
import { stepDetail } from "@/api/codeIncome/analysis";
export default {
  name: "businessUnit",
  components: {
    topBar,
  },
  props: {
    searchData: {
      type: Object,
      default: {},
    },
  },
  watch: {
    searchData: {
      handler(newName) {
          this.getData();
      },
      deep: true,
    },
  },
  data() {
    return {
      title: "台阶收入 - 分来源和细项",
      monthFrom: "",
      increaseFrom: "",
      downFrom: "",
      allFrom: "",
      tableData: [],
      tableTitle: [],
      spanArr1: [],
    };
  },
  created() {},
  mounted() {
    this.getData();
  },
  methods: {
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (row.color2 == "MHB_TOP_0" && columnIndex == "7") {
        return "background: #5A8AC6;padding:0;color:black";
      } else if (row.color2 == "MHB_TOP_1" && columnIndex == "7") {
        return "background: #7BA1D2;padding:0;color:black";
      } else if (row.color2 == "MHB_TOP_2" && columnIndex == "7") {
        return "background: #D9E4F3;padding:0;color:black";
      } else if (row.color2 == "MHB_OFF_0" && columnIndex == "7") {
        return "background: #F8696B;padding:0;color:black";
      } else if (row.color2 == "MHB_OFF_1" && columnIndex == "7") {
        return "background: #F98E95;padding:0;color:black";
      } else if (row.color2 == "MHB_OFF_2" && columnIndex == "7") {
        return "background: #FABCBE;padding:0;color:black";
      }
      return "color:black;padding:0";
    },
    // 获取码号收入整体趋势
    getData() {
      stepDetail({
        cycleValue: this.searchData.acctMonth,
        areaId: this.searchData.areaId,
      }).then((res) => {
        if (res.code == 200) {
          res.data.tableMsg.map((item) => {
            if (item.code == "msg1") {
              this.monthFrom = item.msg;
            } else if (item.code == "msg2") {
              this.increaseFrom = item.msg;
            } else if (item.code == "msg3") {
              this.downFrom = item.msg;
            } else if (item.code == "msg4") {
              this.allFrom = item.msg;
            }
          });
          this.tableTitle = res.data.tableTitle;
          this.tableData = res.data.tableData;
          let contactDot = 0;
          let spanArr1 = [];
          this.tableData.forEach((item, index) => {
            if (index === 0) {
              spanArr1.push(1);
            } else {
              if (item.name0 === this.tableData[index - 1].name0) {
                spanArr1[contactDot] += 1;
                spanArr1.push(0);
              } else {
                contactDot = index;
                spanArr1.push(1);
              }
            }
          });
          this.spanArr1 = spanArr1;
        }
      });
    },
    objectMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (this.spanArr1[rowIndex]) {
          return {
            rowspan: this.spanArr1[rowIndex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
  },
};
</script>

<style scoped>
.businessUnit {
  box-sizing: border-box;
  padding: 20px;
  box-shadow: 0px 0px 10px 1px rgb(0 0 0 / 15%);
}
</style>

<style scoped lang="scss">
.businessUnit {
  margin-top: 20px;
}
.connet {
  box-sizing: border-box;
  padding: 0 20px;
  margin-top: 10px;
  .text {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    .cont {
      font-size: 24px;
      line-height: 44px;
      display: flex;
    }
    .square {
      margin-top: 15px;
      margin-right: 15px;
      width: 10px;
      height: 10px;
      background: #000000;
      transform: rotate(45deg);
    }
    .value {
      flex: 1;
      flex-wrap: wrap;
    }
    p {
      display: flex;
      justify-content: flex-start;
      align-items: flex-start;
      padding-left: 40px;
      font-size: 20px;
      .circle {
        width: 4px;
        height: 4px;
        background-color: #000000;
        border-radius: 50%;
        display: inline-block;
        margin-right: 10px;
        margin-top: 10px;
      }
      .msg {
        flex: 1;
      }
    }
  }
  .table {
    width: 100%;
  }
  /deep/ .el-table {
    width: 100%;
  }
}
</style>
